package nsip.scheduling;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import nsip.model.Item;

import org.uncommons.watchmaker.framework.factories.AbstractCandidateFactory;

/**
 *
 * @author Markus Goetz
 */
public class ScheduleFactory extends AbstractCandidateFactory<AbstractSchedule> {

    private List<Item> orders;
    private List<Item> rfqs;
    private double overplanRatio;
    private int currentDay;

    public ScheduleFactory(List<Item> orders, List<Item> rfqs, double overplanRatio, int currentDay) {
        this.orders = orders;
        this.rfqs = rfqs;
        this.overplanRatio = overplanRatio;
        this.currentDay = currentDay;

        Collections.sort(this.orders, new DeadlineComparator());
    }

    @Override
    public AbstractSchedule generateRandomCandidate(Random random) {
        SeedSchedule schedule = new SeedSchedule(overplanRatio, currentDay, random);

        // First place accepted orders
        for (Item order: orders) {
            schedule.placeOrder(order);
        }

        // Then fill schedule with rfqs
        schedule.fillWith(rfqs);

        // Finally return it
        return schedule;
    }
}
